package cn.com.thingo.hyintelligent.presenter;

import java.util.List;

import javax.inject.Inject;

import cn.com.thingo.hyintelligent.base.RxPresenter;
import cn.com.thingo.hyintelligent.base.contract.EzDeviceAuthorizationContract;
import cn.com.thingo.hyintelligent.model.DataManager;
import cn.com.thingo.hyintelligent.model.bean.BaseBean;
import cn.com.thingo.hyintelligent.model.bean.EzDeleteDevicePermissionBean;
import cn.com.thingo.hyintelligent.model.bean.EzDeviceAuthorizationListBean;
import cn.com.thingo.hyintelligent.util.LogUtil;
import cn.com.thingo.hyintelligent.util.RxUtil;
import io.reactivex.functions.Consumer;

public class EzDeviceAuthorizationPresenter extends RxPresenter<EzDeviceAuthorizationContract.View> implements EzDeviceAuthorizationContract.Presenter {
    private DataManager dataManager;

    @Inject
    public EzDeviceAuthorizationPresenter(DataManager dataManager) {
        this.dataManager = dataManager;
    }


    @Override
    public void deleteEzDevicePermission(String accessToken, String tel, String toTel, String deviceSerial) {
        addSubscribe(dataManager.deleteEzDevicePermission(accessToken, tel, toTel, deviceSerial).compose(RxUtil.<BaseBean>rxSchedulerHelper()).subscribe(new Consumer<BaseBean>() {
            @Override
            public void accept(BaseBean bean) throws Exception {
                mView.viewDeleteDevicePermission(bean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                LogUtil.e(throwable.getMessage());
            }
        }));
    }

    @Override
    public void getDevicePermissionList(String accessToken, String tel, String toTel) {
        addSubscribe(dataManager.getEzDeviceAuthorzationList(accessToken, tel, toTel).compose(RxUtil.<BaseBean<List<EzDeviceAuthorizationListBean>>>rxSchedulerHelper()).subscribe(new Consumer<BaseBean<List<EzDeviceAuthorizationListBean>>>() {
            @Override
            public void accept(BaseBean<List<EzDeviceAuthorizationListBean>> bean) throws Exception {
                mView.viewGetDevicePermissionList(bean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                LogUtil.e(throwable.getMessage());
            }
        }));
    }
}
